import { BreadcrumbState } from '@/redux/interface';
import * as types from '@/redux/mutation-types';
import { Draft, produce } from 'immer';

const breadcrumbState: BreadcrumbState = {
  breadcrumbList: {},
};

export type ActionType = {
  type: typeof types.SET_BREADCRUMBS_LIST;
  breadcrumbList: BreadcrumbState;
};

const breadcrumb = (state: BreadcrumbState = breadcrumbState, action: ActionType) => {
  return produce(state, (draftState: Draft<BreadcrumbState>) => {
    switch (action.type) {
      case types.SET_BREADCRUMBS_LIST:
        draftState.breadcrumbList = action.breadcrumbList;
        break;
      default:
        break;
    }
  });
};

export default breadcrumb;
